﻿using ACC.Business;
using ACC.Business.Process;
using ACC.Business.Stn;
using ACC.Data;
using ACC.Data.ACCLog;
using ACC.Data.Comm;
using ACC.Data.Entities.Mes;
using ACC.Data.Line;
using ACC.Device;
using ACC.Interface.Extensions;
using ACC.LineDevice.KukaPack;
using System;

namespace Script
{

    public class L1P11019 : StnProcessKukaPack
    {
        public L1P11019(StnRunningData data)
            : base(data)
        {
        }
        protected override ACCDevice CreateDevice()
        {
            ACCDevice dev = base.CreateDevice();
            if (kukaSiemensDev != null)
            {
                kukaSiemensDev.DB190 = 800;
                kukaSiemensDev.DB190_Offset = 41000;
                kukaSiemensDev.DB192 = 80;
                kukaSiemensDev.DB192_PLC_Offset = 41066;

                kukaSiemensDev.DB193 = 800;
                kukaSiemensDev.DB193_PLC_Offset = 41034;
                kukaSiemensDev.DB193_ACC_Offset = 41068;
                kukaSiemensDev.DB194 = 800;
                kukaSiemensDev.DB194_PLC_Offset = 41034;
                kukaSiemensDev.DB194_PLC_Data_Offset = 41078;
            }

            return dev;

        }

        protected override void CreateBusinessLogic()
        {
            base.CreateBusinessLogic();
            _loadProcess = new LoadProcess_L1P11019Ex(_data);
            _unloadProcess = new UnloadProcess_L1P11019Ex(_data);
        }

        public override ACCCode ReadLoadParam(ACCDevice dev, out ACCDevice.LoadParam param)
        {
            ACCCode rs = base.ReadLoadParam(dev, out param);
            if (param != null && !string.IsNullOrEmpty(param.UnitSN))
            {
                StnCfg ng_stn = GetLastWorkStn(param.UnitSN);
                var upCellReport = new SCADAProductOutReport()
                {
                    center_code = _lineData.Line,
                    center_name = _data.StnCfg.LineCfg.Desc,
                    prod_sn = param.UnitSN,
                    palletno = ACCExt.GetPalletBySN1(this, param.UnitSN),
                    down_cell = _data.StnCfg.Name,
                    cell_code = ng_stn == null ? "" : ng_stn.Name,
                    cell_name = ng_stn == null ? "" : ng_stn.Desc
                };
                PublishIotMessage("SCADA-MES-14", upCellReport);
                StnEventLog.Log(_data, StnLog.LogType.Success,
                            string.Format("异常下线{0} UnitSN={1}, ErrorMessage={2}", "成功", param.UnitSN, ""));

            }
            return rs;
        }

    }
    public class LoadProcess_L1P11019Ex : LoadProcess
    {
        public LoadProcess_L1P11019Ex(StnRunningData data)
            : base(data)
        {

        }
        /// <summary>
        ///不需要进行load业务的处理
        /// </summary>
        /// <param name="dev"></param>
        public override void ProcessLoad(ACCDevice dev)
        {

        }
    }

    public class UnloadProcess_L1P11019Ex : UnloadProcess
    {
        public UnloadProcess_L1P11019Ex(StnRunningData data)
            : base(data)
        {
        }

        public override void ProcessUnload(ACC.Device.ACCDevice dev)
        {

        }
    }
}